package com.couldsail.takeaway.controller.user;


import com.couldsail.takeaway.common.result.Result;
import com.couldsail.takeaway.pojo.dto.UserCouponReceiveDTO;
import com.couldsail.takeaway.pojo.entity.Coupon;
import com.couldsail.takeaway.pojo.vo.CouponVO;
import com.couldsail.takeaway.pojo.vo.UserCouponVO;
import com.couldsail.takeaway.service.CouponService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user/coupon")
@Api(tags = "用户优惠券相关接口")
@Slf4j
@RequiredArgsConstructor
@CrossOrigin(origins = "*")
public class CouponController {
    private final CouponService couponService;

    @GetMapping("/list")
    @ApiOperation("查询用户优惠券")
    public Result<List<UserCouponVO>> list(UserCouponReceiveDTO userCouponReceiveDTO) {
        log.info("查询用户优惠券 店铺id{}",userCouponReceiveDTO);
        return Result.success(couponService.getUserCoupons(userCouponReceiveDTO));
    }

    @PostMapping("/obtain")
    @ApiOperation("领取优惠券")
    public Result<String> obtain(@RequestParam String couponId) {
        log.info("领取优惠券{}",couponId);
        couponService.obtainCoupon(couponId);
        return Result.success();
    }

    @PostMapping("/detail")
    @ApiOperation("查询优惠券详情")
    public Result<CouponVO> detail(@RequestParam String couponId) {
        log.info("查询优惠券详情{}",couponId);
        return Result.success(couponService.detailCoupon(couponId));
    }
} 